package com.coding.kan_yi_dao.service.impl;

import com.coding.kan_yi_dao.common.Result;
import com.coding.kan_yi_dao.entity.GoodsHot;
import com.coding.kan_yi_dao.entity.GoodsNew;
import com.coding.kan_yi_dao.mapper.GoodsHotMapper;
import com.coding.kan_yi_dao.service.IGoodsHotService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 砍一刀，不买就砍你一刀
 * @since 2023-09-20
 */
@Service
public class GoodsHotServiceImpl extends ServiceImpl<GoodsHotMapper, GoodsHot> implements IGoodsHotService {
    @Resource
    GoodsHotMapper goodsHotMapper;

    //全查询
    @Override
    public Result go_select_all() {
        List<GoodsHot> a = query().eq("goods_hot_delete", 1).list();
        return Result.ok(a);
    }

    //添加
    @Override
    public Result go_insert(GoodsHot goodsHot) {
        Integer a = baseMapper.insert(goodsHot);
        return Result.ok(a);
    }

    //修改
    @Override
    public Result go_update(GoodsHot goodsHot) {
        Integer a = baseMapper.updateById(goodsHot);
        return Result.ok(a);
    }

    //删除
    @Override
    public Result go_delete(List<Integer> ids) {
        List<GoodsHot> goodsHot = new ArrayList<>();
        for (int i = 0; i < ids.size(); i++) {
            GoodsHot goodsHots = new GoodsHot();
            goodsHots.setGoodsHotId(ids.get(i));
            goodsHots.setGoodsHotDelete(0);
            goodsHot.add(goodsHots);
        }
        return Result.ok(updateBatchById(goodsHot));
    }

    //多表查询
    @Override
    public Result go_selectall(GoodsHot goodsHot) {
        Integer b = goodsHot.getGoodsHotId();
        List<GoodsHot> a =goodsHotMapper.go_selectall(b);
        return Result.ok(a);
    }
}
